home *** CD-ROM | disk | FTP | other *** search
- class smashing.Viewport
- {
- static var centerY;
- static var x;
- static var halfWidth;
- static var width;
- static var halfHeight;
- static var height;
- static var centerX;
- static var y;
- static var startX;
- static var startY;
- static var z = 0;
- static var focal = 1300;
- function Viewport()
- {
- }
- static function init(nWidth, nHeight)
- {
- if(nWidth == undefined)
- {
- nWidth = Stage.width;
- }
- if(nHeight == undefined)
- {
- nHeight = Stage.height;
- }
- Stage.scaleMode = "showAll";
- smashing.Viewport.x = nWidth / 2;
- smashing.Viewport.y = nHeight / 2;
- smashing.Viewport.halfWidth = nWidth / 2;
- smashing.Viewport.halfHeight = nHeight / 2;
- smashing.Viewport.width = nWidth;
- smashing.Viewport.height = nHeight;
- smashing.Viewport.centerX = smashing.Viewport.x;
- smashing.Viewport.centerY = smashing.Viewport.y;
- smashing.Viewport.startX = smashing.Viewport.x;
- smashing.Viewport.startY = smashing.Viewport.y;
- Stage.scaleMode = "noScale";
- }
- static function getPos(o)
- {
- var _loc1_ = new smashing.RenderResult();
- var _loc4_ = o.x - smashing.Viewport.x;
- var _loc5_ = o.y - smashing.Viewport.y;
- var _loc3_ = o.z - smashing.Viewport.z;
- _loc1_.x = _loc4_;
- o.mpX = _loc4_;
- _loc1_.y = _loc5_;
- o.mpY = _loc5_;
- _loc1_.scale = smashing.Viewport.focal / (smashing.Viewport.focal + _loc3_);
- o.mpZ = _loc3_;
- return _loc1_;
- }
- static function localize(p)
- {
- return new smashing.Point3D(p.x - smashing.Viewport.x,p.y - smashing.Viewport.y,p.z - smashing.Viewport.z);
- }
- static function getFocal(p)
- {
- var _loc1_ = new smashing.Point3D(p.x - smashing.Viewport.x,p.y - smashing.Viewport.y,p.z - smashing.Viewport.z);
- var _loc2_ = smashing.Viewport.focal / (smashing.Viewport.focal + _loc1_.z);
- return new smashing.Point(_loc1_.x * _loc2_ + smashing.Viewport.centerX,_loc1_.y * _loc2_ + smashing.Viewport.centerY);
- }
- static function getScaleMod(zd)
- {
- return smashing.Viewport.focal / (smashing.Viewport.focal + zd);
- }
- static function reset()
- {
- smashing.Viewport.x = smashing.Viewport.startX;
- smashing.Viewport.y = smashing.Viewport.startY;
- smashing.Viewport.z = 0;
- }
- }
-